'use server'

import { prisma } from '@/lib/prisma'
import { revalidatePath } from 'next/cache'

export async function createCategory(data: { name: string }) {
  const category = await prisma.category.create({
    data: {
      name: data.name
    }
  })

  revalidatePath('/dashboard/inventory/categories')
  return category
}

export async function updateCategory(id: number, data: { name: string }) {
  const category = await prisma.category.update({
    where: { id },
    data: {
      name: data.name
    }
  })

  revalidatePath('/dashboard/inventory/categories')
  return category
}

export async function deleteCategory(id: number) {
  const category = await prisma.category.delete({
    where: { id }
  })

  revalidatePath('/dashboard/inventory/categories')
  return category
} 